package com.yanqu.road.server.logic.bag;

import com.yanqu.road.entity.activity.suitang.config.SuiTangConfigSync;
import com.yanqu.road.entity.bag.UseGoodsResult;
import com.yanqu.road.entity.config.goods.GoodsInfo;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.suitang.SuiTangModule;
import com.yanqu.road.server.manger.activity.ActivityMgr;
import com.yanqu.road.server.manger.activity.suitang.SuiTangMgr;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.utils.date.DateHelper;

/**
 * 隋唐使用幕兵令
 */
public class UseSuiTangMuBingLing extends BaseUseGoods {

    public UseSuiTangMuBingLing(GamePlayer player, GoodsInfo goodsInfo, long param) {
        super(player, goodsInfo, param);
    }

    @Override
    int checkUse(long count) {
        // 检测是否在有效期
        SuiTangConfigSync config = SuiTangMgr.getConfig();
        if (config == null || !ActivityMgr.activityInShowTime(config.getActivityInfo())) {
            return GameErrorCode.E_ACTIVITY_NO_FOUND;
        }
        if (config != null && ActivityMgr.activityInShowTime(config.getActivityInfo()) && !config.inEnterActivityTime()) {
            return GameErrorCode.E_SUI_TANG_NO_OPERATE_TIME;
        }
        long stage1BeginTime = config.getStage1TimeList().get(0).get(0);
        long zeroTimeStamp = DateHelper.getZeroTimeStamp(stage1BeginTime) + 10 * DateHelper.MINUTE_MILLIONS;
        long now = System.currentTimeMillis();
        if (now < zeroTimeStamp) {
            return GameErrorCode.E_SUI_TANG_NO_OPERATE_TIME;
        }
        return 0;
    }

    @Override
    UseGoodsResult executeUse(long count) {
        UseGoodsResult result = new UseGoodsResult();
        SuiTangConfigSync config = SuiTangMgr.getConfig();
        if (config != null && ActivityMgr.activityInShowTime(config.getActivityInfo())) {
            player.getModule(SuiTangModule.class).useMuBingNum(goodsInfo, count);
        }
        result.setReward("");
        return result;
    }
}
